<?php
class ModuleFactory
{
    public function getInstance($module_path, $param=array())
    {
        $module_name = self::loadModuleFile($module_path);
        $module = new $module_name; 
        if (is_array($param) && !empty($param)) {
            foreach ($param as $obj) {
                $property = $obj->name;
                if (property_exists($module, $property)) {
                    $module->$property = $obj->value;
                }
            }
        }
        return $module;
    }

    public static function loadModuleFile($path)
    {
        $path = explode('.', $path);
        $file = implode('/', $path) . '.class.php';
        require_once($file);
        return $path[count($path)-1];
    }
}
